<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <button onclick="alert(456)">xxx</button>

  <hr>

  <input type="text">

  <script>
    //获取button
    let btn = document.querySelector('button');
    let input = document.querySelector('input');

    //为按钮绑定单击事件
    btn.onclick = function(e){
      this.style.background = '#333';
      console.log(e);
    }

    //为 input 绑定 change 事件
    input.onchange = function(){
      console.log('改变啦');
    }

    input.oninput = function(){
      console.log('输入了内容');
    }

    // //DOM 0
    // btn.onclick = function(){}

    // //DOM 2
    // btn.addEventListener('click', function(){

    // })
  </script>
</body>
</html>